// pages/volunteer/volunteer.js
Page({
  data: {
    userInfo: {
      name: '晴天',
      volunteerId: '123444890',
      totalPoints: 109346,
      redeemedPoints: 200,
      currentPoints: 185
    }
  },

  onLoad: function (options) {
    console.log('志愿者中心页面加载');
    this.loadUserData();
  },

  onShow: function () {
    // 页面显示时刷新数据
    this.refreshData();
  },

  // 加载用户数据
  loadUserData: function () {
    // 从本地存储或服务器获取用户数据
    const userData = wx.getStorageSync('volunteerUserData');
    if (userData) {
      this.setData({
        userInfo: { ...this.data.userInfo, ...userData }
      });
    }
  },

  // 刷新数据
  refreshData: function () {
    // 刷新用户数据
    this.loadUserData();
  },

  // 跳转到签到
  goToCheckin: function () {
    wx.navigateTo({
      url: '/pages/volunteer/checkin'
    });
  },

  // 跳转到活动列表
  goToActivities: function () {
    wx.navigateTo({
      url: '/pages/volunteer/activities'
    });
  },

  // 跳转到积分商城
  goToMall: function () {
    wx.navigateTo({
      url: '/pages/volunteer/mall'
    });
  },

  // 跳转到排行榜
  goToRanking: function () {
    wx.navigateTo({
      url: '/pages/volunteer/ranking'
    });
  },

  // 跳转到消息中心
  goToMessages: function () {
    wx.navigateTo({
      url: '/pages/volunteer/messages'
    });
  },

  // 跳转到注册
  goToRegister: function () {
    wx.navigateTo({
      url: '/pages/volunteer/register'
    });
  },

  // 跳转到活动资讯
  goToNews: function () {
    wx.navigateTo({
      url: '/pages/volunteer/news'
    });
  },

  // 跳转到热点活动
  goToHotActivities: function () {
    wx.navigateTo({
      url: '/pages/volunteer/hot-activities'
    });
  },

  // 跳转到志愿者详情页面
  goToVolunteerDetail: function () {
    wx.navigateTo({
      url: '/pages/volunteer/volunteer-detail'
    });
  },

  // 分享功能
  onShareAppMessage: function () {
    return {
      title: '加入志愿者团队，让生命以另一种方式延续',
      path: '/pages/volunteer/volunteer',
      imageUrl: '/images/share-volunteer.png'
    };
  },

  // 分享到朋友圈
  onShareTimeline: function () {
    return {
      title: '加入志愿者团队，让生命以另一种方式延续',
      imageUrl: '/images/share-volunteer.png'
    };
  },

  // 下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1000);
  }
});
